package com.useeinfo.oa.modules.base.entity;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.tools.DateTimeUtils;
import com.useeinfo.framework.sugar.tools.StringConverters;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * @Auther: xudong.sun
 * @Date: 2018/11/30 16:09
 * @Description: 资料分类表
 */
@Entity
@Table(name = "data_cat")
public class DataCat extends SuperClassEntity<DataCat> {
    private String dataCatName;

    /**
     * 关联企业
     */
    @ManyToOne
    @JoinColumn(name = "enterprise_id")
    private Enterprise enterprise;
    public String getDataCatName() {
        return dataCatName;
    }

    public void setDataCatName(String dataCatName) {
        this.dataCatName = dataCatName;
    }

    public Enterprise getEnterprise() {
        return enterprise;
    }

    public void setEnterprise(Enterprise enterprise) {
        this.enterprise = enterprise;
    }

    @Override
    public JSONObject toJSONObject() {
        JSONObject jsonObject = super.toJSONObject();
        jsonObject.put("dataCatName", StringConverters.null2String(getDataCatName()));
        jsonObject.put("createDate", DateTimeUtils.format(getCreateDate(), "yyyy-MM-dd HH:mm:ss"));
        if(getEnterprise()!=null){
            jsonObject.put("enterpriseName", StringConverters.null2String(getEnterprise().getEnterpriseName()));
        }else{
            jsonObject.put("enterpriseName", "");
        }
        return jsonObject;
    }
}
